var apiUrl=contextPath+"/system/telRecord/getList";
var listVue=new Vue({
  el: '#telRecordList',
  data: {
	  params:{
		  pageSize:10,
		  pageNum:1,
		  recordDate:'1',
		  userDepartmentId:'',
		  createUserId:'',
		  callStatus:'',
		  terminalModel:''
	  },
	  userDepartmentId:"",
	  userId:"",
  	  ppList:[],
  	  userDepartmentList:[],
  	  userList:[],
  	  content:"",
  	  recordUrl:"",
  	  permitBtn:'',
  	  permission:{
 		  downLoad:false,
 		  del:false,
 	  }
  },
  mounted:function(){
	  //初始化权限
	  this.initPermission();
  },
  methods: {
     getList:function() {
    	var _self = this;
    	_self.params.callTimeBeforeStr=$("#callTimeBeforeStr").val();
    	_self.params.callTimeAfterStr=$("#callTimeAfterStr").val();
     	$.ajax({
    		type:'post',
            url: apiUrl,
    	    data:_self.params,
    	    dataType:'json',
    	    success: function(res){
    	    	if(res.res=="1"){
    	    		var rows=res.obj.rows;
        	    	_self.ppList=rows;
        	    	//初始化分页
                	var pages=res.obj.totalPages;
    	        	var current=res.obj.pageNumber;
            	    laypage({
            		  cont: $('#pagination'), //容器。值支持id名、原生dom对象，jquery对象,
            		  pages: pages, //总页数
            		  curr:current,
            		  skip: true, //是否开启跳页
            		  skin: 'molv',
            		  groups: 3, //连续显示分页数
            		  jump: function(obj,first){
            			  if(!first){
            				  _self.params.pageNum=obj.curr;
            				  _self.getList();
            			  }
            		  }
            		});
            	    _self.initCss();
    	    	}else{
    	    		layer.alert(res.resMsg);
    	    	}
    	    	
    	    },
    	    error:function(res){
    	    	
    	    }
    	});   
     },
     initPermission:function(){
    	    var _self = this;
    	    var url=contextPath+"/system/telRecord/getIndex";
    		$.ajax({
    			type: 'post',
    	        url: url,
    		    dataType:'json',
    		    success: function(res){
    		    	if(res.res==1){
    		    		//按钮权限
    		    		_self.permitBtn =res.obj.permitBtn;
	 		    		//初始化通话人
    		    		_self.initDepartment();
    		    		//查询列表
    		    		_self.getList();
    		    	}else{
    		    		window.location.href=contextPath+res.resMsg;
    		    	}
    		    }
    		});
     },
     initDepartment:function(){
    	var _self = this;
 	    var url=contextPath+"/system/user/findAllDept";
 		$.ajax({
 			type: 'post',
 	        url: url,
 		    dataType:'json',
 		    success: function(res){
 		    	if(res.res==1){
 		    		//所有部门
 		    		_self.userDepartmentList=res.obj;
 		    	}else{
 		    		layer.alert("查询失败");
 		    	}
 		    }
 		});
     },
     selectUserDepartment:function(){
    	 var _self = this;
    	 if(_self.params.userDepartmentId){
    		 	var url=contextPath+"/system/user/findUserByDeptId";
    	 		$.ajax({
    	 			type: 'post',
    	 	        url: url,
    	 		    dataType:'json',
    	 		    data:{
    	 		    	deptId:_self.params.userDepartmentId
    	 		    },
    	 		    success: function(res){
    	 		    	if(res.res==1){
    	 		    		//部门员工list
    	 		    		_self.userList=res.obj;
    	 		    	}else{
    	 		    		layer.alert("查询失败");
    	 		    	}
    	 		    }
    	 		});
    	 }else{
    		 _self.userList=null;
    		 _self.params.createUserId=null;
    	 }
     },
     selectRecordDate:function(){
//    	 var _self = this;
//    	 var recordDate=_self.params.recordDate;
    	 
     },
//     initPermission(){
//     	var _self = this;
//     	var objList=JSON.parse(_self.permitBtn);
//  		var del="customer:follow:delete";
//  		var downLoad="customer:follow:downLoad";
//  		for(ob in objList){
//  			var permission=objList[ob];
//  			if(permission==del){
//  				_self.permission.del=true;
//  			}else if(permission==downLoad){
//  				_self.permission.downLoad=true;
//  			}
//  		}
//     },
     clearForm:function(){
//    	 this.params.projectId='';
//    	 this.ppList=[];
//    	 this.projectList=[];
    	 this.userList=[];
    	 this.params.callTimeBeforeStr=null;
    	 this.params.callTimeAfterStr=null;
     	 $("#callTimeBeforeStr").val(null);
     	 $("#callTimeAfterStr").val(null);
     	 this.params.customerName=null;
     	 this.params.endBillableSeconds=null;
     	 this.params.startBillableSeconds=null;
     	 this.params.callStatus="";
     	 this.params.terminalModel="";
     	 this.params.userDepartmentId="";
     	 this.params.createUserId="";
     	 this.params.pageNum=1;
     	 this.params.pageSize=10;
     },
     genjin:function(id,type){
    	 var _self = this;
    	 var url=contextPath+"/customer/customer/getImageList";
	  		$.ajax({
	  			type: 'post',
	  	        url: url,
	  		    data: {
	  		    	objectId:id,
	  		    	imgType:4
	  		    },
	  		    dataType:'json',
	  		    success: function(res){
	  		    	if(type==2){
	  		    		_self.picList=res;
	  		    	}else if(type==3){
	  		    		_self.radioList=res;
	  		    	}
	  		    }
	  		});
     },
     selectCustomerDetail:function(terminalModelId,projectId){
    	 var openUrl=contextPath + "/customer/customer/toDetail?customerId="+terminalModelId+"&projectId="+projectId+"&resourcesCode=menu_0003_0001";
    	 window.open(openUrl);
     },
     listerRadio:function(url){
    	 var _self = this;
//    	 $("#playaudio").attr("src",url);
    	 var html = "<audio id='playaudio' src='"+url+"'preload='auto' controls='controls'>";
    	 $(".modal-body").html(html);
    	 $('audio').audioPlayer();
     },
     downLoad:function(recordUrl){
    	 var fileName = recordUrl.substring(recordUrl.lastIndexOf('/') + 1);
    	 window.location.href=contextPath+'/common/file/downloadFile?fileUrl='+recordUrl+'&fileName='+fileName;
     },
     initCss:function(){
    	  $(".across-show").hover(function(){
              $(this).tooltip('show');
          })
     }
  }
})

Vue.filter('mode', function (value) {
	 if (value == 1) {
         return '来电';
     } else if (value == 2) {
         return '来访';
     }else if (value == 3) {
         return '信息';
     }else if (value == 4) {
         return '去电';
     }else if (value == 5) {
         return '拜访';
     }else if (value == 6) {
         return '系统生成';
     }else if (value == 7) {
         return '微信';
     }
     return val;
});

Vue.filter('billableSeconds', function (value,status) {
	 if (status == 0) {
        return '未取话单';
    } else if (status == 2) {
        return '未接通';
    }else if (status == 1) {
    	var t="";
    	if(value!=status && value!=""){
	    	var min = Math.floor(value/60);
    	    var sec = value % 60;
    	    if(min < 10){t += "0";}
    	        t += min + ":";
    	    if(sec < 10){t += "0";}
    	        t += sec;
	   }
    	return t;
    }
    return value;
});
Vue.filter('terminal', function (value) {
	if (value == 0) {
       return '客户';
    }else if(value == 1){
    	return '外部呼入';
    } else if(value == 2){
    	return '手动拨打';
    } 
    return null;
});


